﻿<script type="text/javascript">
    function endsWith(str, suffix) {
        return str.indexOf(suffix, str.length - suffix.length) !== -1;
    }

    function startWith(str, suffix) {
        return str.indexOf(suffix, 0) !== -1;
    }

    $(document).ready(function () {
        $("#content").css("height", $("#content").parent().height() + "px");
        $("#indexViewIframe").attr("height", $("#indexViewDiv").height() + "px");
    });

    window.onresize = function (event) {
        $("#content").css("height", $("#content").parent().height() + "px");
        $("#indexViewIframe").attr("height", $("#indexViewDiv").height() + "px");
    }



    function refreshTreeView(){
        var treeView = $("#AjaxTreeView").data("tTreeView");
        if($("#AjaxTreeView li.lastEdit").length != 0)
        {
            var lastEdit = $("#AjaxTreeView li.lastEdit");
            var lastEditGP = lastEdit.parent().parent();
            treeView.ajaxRequest(lastEditGP);
            $("#AjaxTreeView li.lastEdit").removeClass("lastEdit");
        }
        else if($("#AjaxTreeView li.lastCreate").length != 0)
        {
            var lastCreate = $("#AjaxTreeView li.lastCreate");
            treeView.ajaxRequest(lastCreate);
            $("#AjaxTreeView li.lastEdit").removeClass("lastCreate");
        }
    }

    function changeViewFrame(newSrc){
        $("#indexViewIframe").attr("src", newSrc);
    }

    AjaxTreeView_OnLoad = function (e) {
        $('#AjaxTreeView').data('tTreeView').addContextMenu({
            evaluateNode: function (treeview, node) {
                return node.find('ul').length >= 0;
            },
            menuItems: [{
                text: '@Html.R(VirtualPath,"NewPage")',
                onclick: AjaxTreeView_OnNew
            }, {
                text: '@Html.R(VirtualPath,"EditPage")',
                onclick: AjaxTreeView_OnEdit
            }, {
                text: '@Html.R(VirtualPath,"DeletePage")',
                onclick: AjaxTreeView_OnDelete
            }]
        });
    }

    AjaxTreeView_OnNew = function (e) {
        var vid = e.treeview.getItemValue(e.node);
        e.node.addClass("lastCreate");
        $("#indexViewIframe").attr("src","@Url.Action("CreateList", "Main")/" + vid);
        return true;
    }

    AjaxTreeView_OnEdit = function (e) {
        var vid = e.treeview.getItemValue(e.node);
        e.node.addClass("lastEdit");
        $("#indexViewIframe").attr("src","@Url.Action("Edit", "Main")/" + vid);
    }

    AjaxTreeView_OnDelete = function (e) {
        var vid = e.treeview.getItemValue(e.node);
        e.node.addClass("lastEdit");
        $("#indexViewIframe").attr("src","@Url.Action("Delete", "Main")/" + vid);
    }

</script>
